package com.es.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * 描述:
 * es-servlet-
 *
 * @author Derek
 * 创建时间：2022-04-20 11:01
 */
@WebServlet(urlPatterns = "/testResponse")
public class TestResponse extends HttpServlet {
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        //
        String name = request.getParameter("name");
        //这里是 响应到客户端的类型
        response.setContentType("text/html;charset=utf-8");
        //向外响应要通过流
        PrintWriter out = response.getWriter();
        //servlet最最重要的功能
        out.println("<!DOCTYPE html>");
        out.println("<html>");
        out.println("<head>" +
                "<title>我的第一个servlet页面</title>" +

                "</head>");
        out.println("<body>" +
                "<h2>欢迎" +name+"回来</h2>"+
                "</body>");
        out.println("</html>");
        out.flush();


    }
}
